<?php
include_once "xAP-functions/webincludes.php";
echo webpageheader();

// get filter if not it's A
$letter=substr($_GET["q"],0,1);
if($letter==""){
	$letter="A";
}

//A to Z and map
for($i=65;$i<91;$i++){
	$azmenu[chr($i)]=array("name"=>chr($i),"url"=>"contacts.php?q=".chr($i),"active"=>0);
}
	//$azmenu[1]=array("name"=>"Map","url"=>"contacts.php?q=1","active"=>0);
	$azmenu[2]=array("name"=>"Search","url"=>"contacts.php?q=2","active"=>0);
	$azmenu[$letter]["active"]=1;
	
echo LayoutMenu($azmenu);

if($letter==1){
	//map

}
elseif($letter==2){
	//search
		echo "<center><Table><TR><TD><input name='search' size=20></td><TD><input type='submit' value='Search'></td></tr></table></center>";



}
else
{
	// just show the letter
	$sql="Select * from xAP_Contacts where 
 firstname LIKE '$letter%' or 
 lastname LIKE '$letter%' or 
 company LIKE '$letter%' or 
 displayname LIKE '$letter%'
 order by displayname,lastname,Company;";
	$results=dbquery($sql);

	
//header
		$cells[0]=array("Name"=>"Name",
						"HomePhone"=>"Home",
						"BusinessPhone"=>"Work",
						"MobilePhone"=>"Mobile");
	$i=1;
	foreach($results as $row){
		$name=$row["DisplayName"];
		if($name==""){$name=trim($row["FirstName"]." ".$row["LastName"]);}
		$cells[$i]=array("Name"=>"<a href='contact.php?id=".$row["ContactID"]."'>".trim($name." ".$row["Company"])."</a>",
						"HomePhone"=>$row["HomePhone"],
						"BusinessPhone"=>$row["BusinessPhone"],
						"MobilePhone"=>$row["MobilePhone"]);
		
		$i++;
	}
	//function from the layout that draws a grid.
	echo LayoutTable($cells);
}
echo webpagefooter();
?>